﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework;
using System.Windows.Threading;
using Microsoft.Xna.Framework.Audio;
using System.IO;


namespace EventManager
{
    public partial class ScheduleEvent : PhoneApplicationPage
    {
        private Microphone microphone = Microphone.Default;
        private byte[] buffer;
        private MemoryStream stream = new MemoryStream();
        private SoundEffect sound;
        private Event eventObj; 

        private void Record_Click(object sender, EventArgs e)
        {
            microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
            buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
            microphone.Start();
            PageTitle.Text = "Record";
        }
        
        private void Stop_Click(object sender, EventArgs e)
        {
            if (microphone.State == MicrophoneState.Started)
            {
                microphone.Stop();
                PageTitle.Text = "Stop";
            }
            else
            {
                PageTitle.Text = "create event";
            }

            //Send text to Speech to text service for processing
            
        }

        /*private void Play_Click(object sender, EventArgs e)
        {
            sound = new SoundEffect(stream.ToArray(), microphone.SampleRate, AudioChannels.Mono);
            sound.Play();
            PageTitle.Text = "play";
        }*/

        public ScheduleEvent()
        {
            InitializeComponent();
            textBox1.Text = "TASK : \nTIME : \nLOCATION : \nPARTICIPANTS : ";
            PageTitle.Text = "create event";
            microphone.BufferReady += (object sender, EventArgs e) =>
            {
                microphone.GetData(buffer);
                stream.Write(buffer, 0, buffer.Length);
            };

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //NavigationService.Navigate(new Uri("/EventMap.xaml", UriKind.Relative));
            rBtnrecordEvent.IsChecked = false;
            rBtnSetLocation.IsChecked = true;
        }

        private void btnRecordEvent_Click(object sender, RoutedEventArgs e)
        {
            // record event
            rBtnrecordEvent.IsChecked = true;
            rBtnSetLocation.IsChecked = false;
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Buddies.xaml", UriKind.Relative));
        }

    }
}